/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fasea.search.documents;

import fasea.index.filehandler.DocumentType;
import fasea.index.filehandler.FileHandlerException;
import fasea.ui.utils.ImageControl;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Date;
import javax.swing.Icon;
import org.apache.commons.io.FilenameUtils;

/**
 *
 * @author WolframL
 */
public abstract class Document {

    protected org.apache.lucene.document.Document document;

    /**
     * @return the document
     */
    /*
     * public org.apache.lucene.document.Document getDocument() { return
     * document; }
     */
    public String getTitle() {
        String title = document.get("title");
        if (title == null || title.trim().isEmpty()) {
            title = getPath().substring(getPath().lastIndexOf(File.separatorChar) + 1);
        }
        return title;
    }

    public long getSize() {
        return Long.parseLong(document.get("size"));
    }

    public String getFileExtension() {
        return document.get("fileExtension");
    }

    public DocumentType getDocumentType() {
        return DocumentType.parse(document.get("documentType"));
    }

    public Date getLastModified() {
        return new Date(Long.valueOf(document.get("lastModified")));
    }

    public String getPath() {
        return document.get("path");
    }

    /**
     * @param document the document to set
     */
    public void setDocument(org.apache.lucene.document.Document document) {
        this.document = document;
    }

    public Icon getThumbnail() throws FileHandlerException {
        return ImageControl.getImageControl().getThumbnail(getDocumentType());
    }

    public String getText() {
        return document.get("text");
    }

    public abstract String getFragment();
}
